package com.sms.controller;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sms.service.BisSmsRecordService;
import com.system.common.pojo.BisCustomUser;
import com.system.common.pojo.BisSmsRecord;

@Controller
@RequestMapping("sms")
public class BisSmsRecordController {
	@Autowired
	private BisSmsRecordService bisSmsRecordService;
	@RequestMapping("show")
	public String selectAll(Model model, HttpServletRequest request) {
		Map<String, Object> map =initMap(request);
		List<BisSmsRecord> list = bisSmsRecordService.selectAll(map);
		model.addAttribute("bisSmsRecordlist", list);
		List<BisCustomUser> userList=bisSmsRecordService.userList();
		model.addAttribute("userList", userList);
		return "sms/bsrList";
	}

	private Map<String,Object> initMap(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<>();
		
		 String mobile=request.getParameter("mobile");
		 if(mobile!=null&&!mobile.equals("")){
			 map.put("mobile",mobile); }
		 String content=request.getParameter("content");
		 if(content!=null&&!content.equals("")){ map.put("content",content); }
		 String smsType=request.getParameter("smsType");
		 if(smsType!=null&&!smsType.equals("")){ map.put("smsType",smsType); }
		 String createTime=request.getParameter("createTime");
		 if(createTime!=null&&!createTime.equals("")){
		 map.put("createTime",createTime); } String
		 endTime=request.getParameter("endTime");
		 if(endTime!=null&&!endTime.equals("")){ map.put("endTime",endTime); }
		 String sendTime=request.getParameter("sendTime");
		 if(sendTime!=null&&!sendTime.equals("")){
		 map.put("sendTime",sendTime); } String
		 sendEndTime=request.getParameter("sendEndTime");
		 if(sendEndTime!=null&&!sendEndTime.equals("")){
		 map.put("sendEndTime",sendEndTime); } String
		 status=request.getParameter("status");
		 if(status!=null&&!status.equals("")){ map.put("status",status); }
		return map;
	}
	@RequestMapping("delete")
	public String delete(String recordId){
	    bisSmsRecordService.delete(recordId);
		return "redirect:/sms/show";
	}
	@RequestMapping("save")
	public String add(HttpServletRequest request){
		String address=request.getParameter("mobile");
		String content=request.getParameter("contents");
		String[] res=address.split(","); 
		for (int i = 0; i < res.length; i++) {
			bisSmsRecordService.save(res[i], content);
		}
		return "redirect:/sms/show";
	}
}
